#!/bin/awk -f
BEGIN{
  for(i=1;i<ARGC;i++){
    n=split(ARGV[i],a,"=");
    if(n==2){
      if(a[1]=="conf"){
	fext=a[2];
	nn=split(a[2],z0,"");
      }
      if(a[1]=="orbs"){
	oo=split(a[2],orb,",");
      }
    }else{
      fn=ARGV[i];
    }
  }
  for(i=1;i<=nn;i++){
    for(j in orb){
      argu=orb[j]" NODE_"i;
      z[argu]=z0[i]/2;
#      print i,argu," : "z[argu];
    };
  }
  ARGC=2; if(fn!=""){ARGV[1]=fn}else{ARGV[1]="-"};
  fo="xyz."fext;
}
FNR<5{print $0>fo }
FNR>4{
  argu=$6" "$7;
  if(z[argu]!=""){zz=$3+z[argu]}else{zz=$3};
  sh="-";
  if(z[argu]!=""){sh="shift+"z[argu]};
  printf("%13.8f %13.8f %10.6f %5i %3i %5s %s %s\n",$1,$2,bound(zz),$4,$5,$6,$7,sh)>fo;
}
END{}
function bound(y, z){z=y-int(y);if(z<-0.5){z+=1.0};if(z>=0.5){z+=-1.0};return z}
